<?

require_once("session.php");
require_once("utilities.php");

SESSION();


function captcha_image() {

    header("Content-Type: image/png");
    
    $im = @imagecreate(170, 45) or die("Cannot Initialize new GD image stream");
    
    $background_color = imagecolorallocate($im, 255, 255, 255);
    
    $text_color = imagecolorallocate($im, 255, 0, 0);
    
    imagestring($im, 5, 60, 15,  $_SESSION['captcha'], $text_color);
    
    imagepng($im);
    
    imagedestroy($im);

}




function generate_captcha() {

    $_SESSION['captcha'] = rstring(6);

}


function clear_captcha() {

    unset($_SESSION['captcha']);
    unset($_SESSION['verified']);

}


if (@$_GET['op'] == 'generate') {

    generate_captcha();

} if (@$_GET['op'] == 'regenerate') {

    sleep(1);

    generate_captcha();

} else if (@$_GET['op'] == 'image') {

    captcha_image();


} else if (@$_GET['op'] == 'clear') {

    clear_captcha();

} else if (@$_GET['op'] == 'show') {

   //echo $_SESSION['captcha'];
   //echo $_SESSION['verified'];

}


?>


